Future trait
from Rustの非同期処理
Future trait
Rustの標準ライブラリに含まれる
以前から、同名のものが非公式のcrateであるfutures crateに存在していた
Rust v1.39で、よりシンプルなものが標準ライブラリに入った
async fnはで返される型は自動的にFutureを実装される
docs
code:rs
pub trait Future {
type Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>;
}
pub enum Poll<T> {
Ready(T),
Pending,
}
#wip
完了状態(値を返すか、エラーを返すか)をポーリング(poll)することで進行状況を確認できる。
https://rust-lang.github.io/async-book/index.html
https://qiita.com/__pandaman64__/items/9fd47af5a39f0d2a6bbb
effective-rust
https://tech-blog.optim.co.jp/entry/2019/07/05/173000
https://keens.github.io/blog/2019/07/07/rustnofuturetosonorunnerwotsukuttemita/
https://hack.nikkei.com/blog/advent20221213/